#include<bits/stdc++.h>
using namespace std;
#define int long long

inline int fun() {
	char firstChar;
	string op;
	int n, ans = 0;

	while (cin >> firstChar) {
		if (firstChar == ']')	break;
		cin >> op >> n;
		if (firstChar == 'F') {
			ans += n;
		} else if (firstChar == 'B') {
			ans -= n;
		} else {
			getchar();
			ans += n * fun();
			getchar();
		}
	}
	return ans;
}

signed main() {
	int ans = abs(fun());
	cout << ans;
	return 0;
}
